AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "cl_scoreboard.lua" )
AddCSLuaFile( "cl_menu.lua" )
AddCSLuaFile( "SPropProtection/cl_Init.lua" )
AddCSLuaFile( "SPropProtection/sh_CPPI.lua" )
AddCSLuaFile( "hud.lua" )
AddCSLuaFile( "DCollapsibleCategory2.lua" )

include( 'shared.lua' )
include( 'chatcmds.lua' )

resource.AddFile("sound/punch/punch_01.wav")
resource.AddFile("sound/punch/punch_02.wav")
resource.AddFile("sound/punch/punch_03.wav")
resource.AddFile("sound/punch/punch_04.wav")
resource.AddFile("sound/punch/punch_05.wav")
resource.AddFile("sound/punch/punch_06.wav")
resource.AddFile("sound/punch/punch_07.wav")
resource.AddFile("sound/punch/punch_08.wav")
resource.AddFile("sound/punch/punch_09.wav")
resource.AddFile("sound/punch/punch_10.wav")
resource.AddFile("beep.wav")

resource.AddFile("materials/money/goldbar.vmt")
resource.AddFile("materials/money/goldbar.vtf")
resource.AddFile("materials/money/silvcoin.vmt")
resource.AddFile("materials/money/silvcoin.vtf")

resource.AddFile("models/money/goldbar.dx80.vtx")
resource.AddFile("models/money/goldbar.dx90.vtx")
resource.AddFile("models/money/goldbar.mdl")
resource.AddFile("models/money/goldbar.phy")
resource.AddFile("models/money/goldbar.sw.vtx")
resource.AddFile("models/money/goldbar.vvd")

resource.AddFile("models/money/silvcoin.dx80.vtx")
resource.AddFile("models/money/silvcoin.dx90.vtx")
resource.AddFile("models/money/silvcoin.mdl")
resource.AddFile("models/money/silvcoin.phy")
resource.AddFile("models/money/silvcoin.sw.vtx")
resource.AddFile("models/money/silvcoin.vvd")
function GM:PlayerSpawn( ply )
    self.BaseClass:PlayerSpawn( ply )   
 
    ply:SetGravity( 1 )

	ply:SetWalkSpeed( 300 )
	ply:SetRunSpeed( 375 )
	ply:SetHealth(100)
	ply:SetMaxHealth(100, true)
	local info = string.Explode(":", tostring(ply:SteamID()))
	file.Write("rpmoney/"..info[2]..info[3]..".txt", ply:GetNWInt("rpmoney"))
end

function SetModel(ply, cmd, args)
	ply:SetNWString("rpmodel", args[1])
	ply:Spawn()
end
concommand.Add("rp_selmodel", SetModel)

function Citizen(ply, cmd, args)
	ply:SetTeam(1)
	ply:Spawn()
	ply:EmitSound("beep.wav")
end
concommand.Add("rp_citizen", Citizen)

function Geek(ply, cmd, args)
	ply:SetTeam(2)
	ply:Spawn()
	ply:EmitSound("beep.wav")
end
concommand.Add("rp_geek", Geek)

function GM:PlayerLoadout( ply )
	ply:Give( "hands" )
	ply:Give( "weapon_physcannon" )
	ply:Give( "weapon_physgun" )
	ply:Give( "gmod_tool" )
	ply:Give( "gmod_camera" )
end

function GM:PlayerSetModel( ply )
	if ply:GetNWString("rpmodel") != "" then
		ply:SetModel(ply:GetNWString("rpmodel"))
	elseif ply:Team() == 1 then
			ply:SetModel( "models/player/Group01/Male_01.mdl" )
	elseif ply:Team() == 2 then
			ply:SetModel( "models/player/Hostage/Hostage_04.mdl" )
	end
end

function GM:PlayerInitialSpawn( ply )
	ply:SetTeam(1)
	local info = string.Explode(":", tostring(ply:SteamID()))
	if file.Exists("rpmoney/"..info[2]..info[3]..".txt") then
		ply:SetNWInt("rpmoney", file.Read("rpmoney/"..info[2]..info[3]..".txt"))
	else
		ply:SetNWInt("rpmoney", 500)
		file.Write("rpmoney/"..info[2]..info[3]..".txt", ply:GetNWInt("rpmoney"))
	end
end

function GM:KeyPress(ply, key)
	local ent = ply:GetEyeTrace().Entity

	if key == IN_USE then
		if ent:IsValid() and not ply:KeyDown(IN_ATTACK) then
			if ent:GetTable().MoneyDrop and ply:EyePos():Distance(ent:GetPos()) < 75 then
				ply:ChatPrint("You recieved "..ent:GetTable().Amount .. " dollars!")
				ply:SetNWInt("rpmoney", ply:GetMoney() + ent:GetTable().Amount)
				ent:Remove()
				ply:EmitSound("physics/metal/chain_impact_hard1.wav")
			end
		end
	end
end

function GM:CanTool(ply, tr, mode)
	local ent = ply:GetEyeTrace().Entity
	if ent:IsValid() then
		if ent.candupe == false and (mode == "weld" or
					mode == "weld_ez" or
					mode == "spawner" or
					mode == "duplicator" or
					mode == "adv_duplicator") then
			return false
		end
	end
	return true
end

local WireTools = {
"wire_rtcam",
"wire_hydraulic",
"wire_addressbus",
"wire_dataplug",
"wire_dataport",
"wire_datarate",
"wire_gpu",
"wire_dynmemory",
"wire_hdd",
"wire_stringbuf",
"wire_sensor",
"wire_locator",
"wire_target_finder",
"wire_waypoint",
"wire_xyzbeacon",
"wire_cpu",
"wire_gate_expression",
"wire_expression2",
"wire_gate_arithmetic",
"wire_gate_comparison",
"wire_gate_logic",
"wire_gate_memory",
"wire_gate_selection",
"wire_gate_string",
"wire_gate_table",
"wire_gate_time",
"wire_gate_trig",
"wire_pid",
"radiosystems",
"wire_cd_disk",
"wire_cd_ray",
"wire_keycard",
"wire_ramcard",
"wire_data_satellitedish",
"wire_data_store",
"wire_data_transferer",
"wire_damage_detector",
"wire_emarker",
"wire_gps",
"wire_gyroscope",
"wire_hsranger",
"wire_las_reciever",
"wire_microphone",
"wire_ranger",
"wire_speedometer",
"wire_watersensor",
"wire_7seg",
"wire_adv_hudindicator",
"wire_consolescreen",
"wire_panel",
"wire_digitalscreen",
"wire_hudindicator",
"wire_indicator",
"wire_lamp",
"wire_light",
"wire_oscilloscope",
"wire_pixel",
"wire_screen",
"wire_soundemitter",
"wire_textscreen",
"wire_colorer",
"wire_hsholoemitter",
"wire_holoemitter",
"wire_hologrid",
"wire_useholoemitter",
"wire_materializer",
"wire_painter",
"wire_trail",
"wire_fx_emitter",
"keypad_wire",
"wire_adv_input",
"wire_adv_pod",
"wire_button",
"wire_string",
"wire_value",
"wire_dual_input",
"wire_eyepod",
"wire_graphics_tablet",
"wire_notifier",
"wire_output",
"wire_input",
"wire_plug",
"wire_pod",
"wire_radio",
"wire_relay",
"wire_textreceiver",
"wire_twoway_radio",
"wire_vehicle",
"wire_keyboard",
"wire_numpad",
"wire_dupeport",
"rt_buoyancy_wire",
"wire_cam",
"dscale",
"wire_facer",
"wire_forcer",
"wire_freezer",
"wire_grabber",
"wire_hoverball",
"wire_motor",
"wire_nailer",
"wire_no_collide",
"wire_spawner",
"wire_servo",
"wire_simple_servo",
"wire_thruster",
"wire_user",
"wire_vthruster",
"wire_weight",
"wire_latch",
"wire_wheel",
"wire_winch",
"wire_magnet",
"xqm_wire_hydraulic",
"wire_debugger",
"wire_wirelink",
"wire_gates",
"multi_wire",
"wire_namer",
"wire",
"wire_adv",
"wire_data_wireless_srv",
"wire_data_wireless_recv",
"wire_rfid_reader_beam",
"wire_rfid_implanter",
"wire_rfid_reader_prox",
"wire_rfid_filter",
"wire_rfid_reader_act",
"wire_ranger_beta",
"wire_target_finder_beta",
"wnpc",
"Dynamite",
"Ignite",
"turret",
"wire_explosive",
"wire_simple_explosive",
"wire_field_device",
"wire_turret",
"wire_detcord",
"wire_detonator"
}
function GeekOnly(pl, tr, tool)
	for k,v in pairs(WireTools) do
		if tool == v then
			if pl:Team() != 2 then
				pl:ChatPrint("You have to be a geek to use this")
				return false
			end
		end
	end
end
hook.Add( "CanTool", "WireForGeek", GeekOnly )